package com.gupaoedu.pattern.singleton.destroy;

import com.gupaoedu.pattern.singleton.lazy.LazyDoubleCheckSingleton;

import java.lang.reflect.Constructor;

/**
 * 2019/5/11
 * created by chenpp
 * 虽然构造方法私有化了,反射可以破坏单例
 */
public class ReflectDestroySingletonTest {
    public static void main(String[] args) {
        try {
            Class<?> clazz = LazyDoubleCheckSingleton.class;
            //获取无参构造方法
            Constructor constructor =  clazz.getDeclaredConstructor();
            //私有方法 强吻
            constructor.setAccessible(true);
            Object instance = constructor.newInstance();
            System.out.println(instance);
            System.out.println(LazyDoubleCheckSingleton.getInstance());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
